const app = getApp();
var api = require('../../../api.js');
var mta = require('../../../mta_analysis.js');

Page({
  data: {
    list: [],
    number: 0,
    total: 0,
    zero: "您还没有好友，请加油！",
    judge: 0,
  },
  onLoad: function (options) {
    mta.Page.init();
    app.bind();
    this.getFriend();
  },
  onReady: function () {

  },
  onShow: function () {

  },
  onHide: function () {
    var url = app.getcurrentPage();
    wx.setStorageSync("from_url", url);
  },
  onUnload: function () {

  },
  onPullDownRefresh: function () {

    app.bind();
    this.getFriend();
    
    // 显示顶部刷新图标  
    wx.showNavigationBarLoading();

    // 隐藏导航栏加载框  
    wx.hideNavigationBarLoading();

    //停止下拉刷新
    wx.stopPullDownRefresh();

  },
  onReachBottom: function () {

  },
  onShareAppMessage: function () {
    var url = app.getcurrentPage();
    var user_id = wx.getStorageSync('user_id');
    return {
      path: url + "?user_id=" + user_id,
      title: '得道1314'
    };  
  },
  getFriend:function(){
    var that = this;
    var access_token = wx.getStorageSync('access_token');
    console.log(access_token);
    var url = api.passport.getteam;
    wx.request({
      url: url,
      method: "post",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        access_token: access_token
      },
      success:function(e){
        console.log(e.data[1].f_c)
        var list = e.data[1].f_c;
        console.log(list.length);

        if (list.length == 0) {
          that.setData({
            judge: 1,
          }) 
        }
        
        that.setData({
          list: list,
          number: list.length,
        })
      }
    })
  }

})